home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / CMATH.ZIP / COSH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  1.1 KB  |  69 lines

  1. /*                            cosh.c
  2.  *
  3.  *    Hyperbolic cosine
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * double x, y, cosh();
  10.  *
  11.  * y = cosh( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns hyperbolic cosine of argument in the range MINLOG to
  18.  * MAXLOG.
  19.  *
  20.  * cosh(x)  =  ( exp(x) + exp(-x) )/2.
  21.  *
  22.  *
  23.  *
  24.  * ACCURACY:
  25.  *
  26.  *                      Relative error:
  27.  * arithmetic   domain     # trials      peak         rms
  28.  *    DEC       0,2         20000       2.9e-17     8.6e-18
  29.  *    IEEE     +-MAXLOG     30000       2.6e-16     5.7e-17
  30.  *
  31.  *
  32.  * ERROR MESSAGES:
  33.  *
  34.  *   message         condition      value returned
  35.  * cosh overflow    |x| > MAXLOG       MAXNUM
  36.  *
  37.  *
  38.  */
  39.  
  40. /*                            cosh.c */
  41.  
  42. /*
  43. Cephes Math Library Release 2.0:  April, 1987
  44. Copyright 1985, 1987 by Stephen L. Moshier
  45. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  46. */
  47.  
  48. #include "mconf.h"
  49. extern double MAXLOG, MAXNUM;
  50.  
  51. double cosh(x)
  52. double x;
  53. {
  54. double y;
  55. double exp(), ldexp();
  56.  
  57. if( x < 0 )
  58.     x = -x;
  59. if( x > MAXLOG )
  60.     {
  61.     mtherr( "cosh", OVERFLOW );
  62.     return( MAXNUM );
  63.     }    
  64. y = exp(x);
  65. y = y + 1.0/y;
  66. y = ldexp( y, -1 );
  67. return( y );
  68. }
  69.